package com.easyUploader.threadHolder;

import com.easyUploader.entity.dao.User;
import com.easyUploader.entity.dto.UserDto;
import com.easyUploader.entity.vo.UserVo;

import static com.easyUploader.entity.factory.UserFactory.USER_CONVERTER;

/**
 * @author 大忽悠
 * @create 2022/11/19 15:10
 */
public class UserThreadHolder {
    private static final ThreadLocal<UserDto> USER = new ThreadLocal<>();

    public static UserDto get() {
        return USER.get();
    }

    public static void set(UserDto user) {
        USER.set(user);
    }

    public static void clear() {
        USER.set(null);
    }

    public static void set(User user) {
        set(USER_CONVERTER.toUserDto(user));
    }

    public static void set(UserVo userVo) {
        set(USER_CONVERTER.toUserDto(USER_CONVERTER.toUser(userVo)));
    }
}
